﻿@{
    Layout = "~/Views/Shared/_Index.cshtml";
 }
<div class="container-div">
    <div class="row">
        @* <div id="searchDiv" class="col-sm-12 search-collapse"> *@
        @*     <div class="select-list"> *@
        @*         <ul> *@
        @*             <li> *@
        @*                 shop_name：<input id="shop_name" col="shop_name" type="text" /> *@
        @*             </li> *@
        @*             <li> *@
        @*                 <a id="btnSearch" class="btn btn-primary btn-sm" onclick="searchGrid()"><i class="fa fa-search"></i>&nbsp;搜索</a> *@
        @*             </li> *@
        @*         </ul> *@
        @*     </div> *@
        @* </div> *@
        <div class="btn-group-sm hidden-xs" id="toolbar">
            @* <a id="btnAdd" class="btn btn-success" onclick="showSaveForm(true)"><i class="fa fa-plus"></i> 新增</a> *@
            <a id="btnEdit" class="btn btn-primary disabled" onclick="showSaveForm(false)"><i class="fa fa-edit"></i> 修改</a>
            @* <a id="btnDelete" class="btn btn-danger disabled" onclick="deleteForm()"><i class="fa fa-remove"></i> 删除</a> *@
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="gridTable" data-mobile-responsive="true"></table>
        </div>
    </div>
</div>

<script type="text/javascript">
    $(function () {
        initGrid();
    });


    let checkboxOptions = [
      {
        name: '新车销售',
        value: '1'
      },
      {
        name: '二手车',
        value: '2'
      },
      {
        name: '二手车寄售',
        value: '3'
      },
      {
        name: '租赁',
        value: '4'
      },
      {
        name: '维保',
        value: '5'
      }
    ];

    function GetbusinessCategories(value) {
       let valuesToFilter = value.split(",").map(Number);
             // 使用filter方法来分割数组，根据value属性在valuesToFilter中的选项
       let filteredOptions = checkboxOptions.filter(option => valuesToFilter.includes(Number(option.value)));

        // 提取每个选项的name属性
       let names = filteredOptions.map(option => option.name);

        // 将数组转换为逗号分隔的字符串
       let resultString = names.join(",");
       return resultString;
    }

    function initGrid() {
        var queryUrl = '@Url.Content("~/QixingManage/ShopApplications/GetPageListJson")';
        $('#gridTable').ysTable({
            url: queryUrl,
            columns: [
                { checkbox: true, visible: true },
                { field: 'Id', title: 'Id', visible: false },
                { field: 'shop_name', title: '店铺名称' },
                { field: 'address', title: '店铺地址' },
                { field: 'owner_name', title: '经营者姓名' },
                { field: 'phone', title: '联系电话' },
                { field: 'business_categories', title: '经营类目', formatter: function (value, row, index) {
                      return GetbusinessCategories(row.business_categories)
                    }
                },
                { field: 'apply_time', title: '申请时间' },
                 { field: 'status', title: '审核状态', formatter: function (value, row, index) {
                      return row.status==0? "待审核" :row.status==1? "通过":"拒绝"
                    } 
                 },
            ],
            queryParams: function (params) {
                var pagination = $('#gridTable').ysTable('getPagination', params);
                var queryString = $('#searchDiv').getWebControls(pagination);
                return queryString;
            }
        });
    }

    function searchGrid() {
        $('#gridTable').ysTable('search');
        resetToolbarStatus();
    }

    function showSaveForm(bAdd) {
        var id = 0;
        if (!bAdd) {
            var selectedRow = $('#gridTable').bootstrapTable('getSelections');
            if (!ys.checkRowEdit(selectedRow)) {
                return;
            }
            else {
                id = selectedRow[0].Id;
            }
        }
        ys.openDialog({
            title: id > 0 ? '编辑' : '添加',
            content: '@Url.Content("~/QixingManage/ShopApplications/ShopApplicationsForm")' + '?id=' + id,
            width: '768px',
            height: '550px',
            callback: function (index, layero) {
                var iframeWin = window[layero.find('iframe')[0]['name']];
                iframeWin.saveForm(index);
            }
        });
    }

    function deleteForm() {
        var selectedRow = $('#gridTable').bootstrapTable('getSelections');
        if (ys.checkRowDelete(selectedRow)) {
            ys.confirm('确认要删除选中的' + selectedRow.length + '条数据吗？', function () {
                var ids = ys.getIds(selectedRow);
                ys.ajax({
                    url: '@Url.Content("~/QixingManage/ShopApplications/DeleteFormJson")' + '?ids=' + ids,
                    type: 'post',
                    success: function (obj) {
                        if (obj.Tag == 1) {
                            ys.msgSuccess(obj.Message);
                            searchGrid();
                        }
                        else {
                            ys.msgError(obj.Message);
                        }
                    }
                });
            });
        }
    }
</script>
